//初始化工厂类
import * as contants from './constants'
import {  fromJS  } from 'immutable';
import axios from 'axios';

export const searchFocus = () =>({
  type: contants.SEARCH_FOCUS
});
export const searchBlur = () =>({
  type: contants.SEARCH_BLUR
});
export const getList =()=>{
  return (dispatch) => {
    axios.get('/api/headerList.json').then((res)=>{
      //success
      const data = res.data;
      dispatch(changeList(data.data));
    }).catch(()=>{
      //error
    })
  }
};
export const mouseEnter=()=>({
  type: contants.MOUSE_ENTER
});
export const mouseLeave=()=>({
  type: contants.MOUSE_LEAVE
});
export const changePage=(page)=>({
  type: contants.CHANGE_PAGE,
  page:page
});

const changeList = (data) =>({
  type: contants.CHANGE_LIST,
  data: fromJS(data),
  totalPage:Math.cell(data.lenght/10)
});